package com.modakai.med.common.handler;

import com.modakai.med.common.exception.MedException;
import com.modakai.med.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<String> error(Exception e){
        log.error("系统发生异常 ", e);
        return Result.fail();
    }

    /**
     * 自定义异常处理方法
     * @param e
     */
    @ExceptionHandler(MedException.class)
    public Result<String> error(MedException e){
        return Result.build(e.getCode(), e.getMessage());
    }
}

